package com.hkts.naturalgas.alarminformation.service.serviceimpl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hkts.naturalgas.alarminformation.entity.NaturalgasGateStation;
import com.hkts.naturalgas.alarminformation.mapper.NaturalgasGateStationMapper;
import com.hkts.naturalgas.alarminformation.service.INaturalgasGateStationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.apache.commons.lang.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import java.util.List;
/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yck
 * @since 2020-09-11
 */
@Service
@Transactional
public class NaturalgasGateStationServiceImpl extends ServiceImpl<NaturalgasGateStationMapper, NaturalgasGateStation> implements INaturalgasGateStationService {


@Autowired
private NaturalgasGateStationMapper naturalgasGateStationMapper;

@Override
public IPage<NaturalgasGateStation> selectPage(Page<NaturalgasGateStation> page, NaturalgasGateStation naturalgasGateStation){
        QueryWrapper<NaturalgasGateStation> query = Wrappers.query();
        QueryWrapper<NaturalgasGateStation> entityWrapper = getEntityWrapper(query, naturalgasGateStation);
        return naturalgasGateStationMapper.selectPage(page, entityWrapper);
        }




@Override
public List<NaturalgasGateStation> selectList(NaturalgasGateStation naturalgasGateStation){
        QueryWrapper<NaturalgasGateStation> query = Wrappers.query();
        QueryWrapper<NaturalgasGateStation> entityWrapper = getEntityWrapper(query, naturalgasGateStation);
        return naturalgasGateStationMapper.selectList(entityWrapper);
        }

/**
 *  公共查询条件
 * @param entityWrapper
 * @return
 */
public QueryWrapper<NaturalgasGateStation> getEntityWrapper(QueryWrapper<NaturalgasGateStation> entityWrapper,NaturalgasGateStation naturalgasGateStation){
        //条件拼接
                if(StringUtils.isNotBlank(naturalgasGateStation.getCreateBy())){
                entityWrapper.like(NaturalgasGateStation.CREATE_BY,naturalgasGateStation.getCreateBy());
                }

                if(StringUtils.isNotBlank(naturalgasGateStation.getUpdateBy())){
                entityWrapper.like(NaturalgasGateStation.UPDATE_BY,naturalgasGateStation.getUpdateBy());
                }

                if(StringUtils.isNotBlank(naturalgasGateStation.getGateName())){
                entityWrapper.like(NaturalgasGateStation.GATE_NAME,naturalgasGateStation.getGateName());
                }
                if(StringUtils.isNotBlank(naturalgasGateStation.getGateState())){
                entityWrapper.like(NaturalgasGateStation.GATE_STATE,naturalgasGateStation.getGateState());
                }
                if(StringUtils.isNotBlank(naturalgasGateStation.getGateType())){
                entityWrapper.like(NaturalgasGateStation.GATE_TYPE,naturalgasGateStation.getGateType());
                }
                if(StringUtils.isNotBlank(naturalgasGateStation.getLatitude())){
                entityWrapper.like(NaturalgasGateStation.LATITUDE,naturalgasGateStation.getLatitude());
                }
                if(StringUtils.isNotBlank(naturalgasGateStation.getLongitude())){
                entityWrapper.like(NaturalgasGateStation.LONGITUDE,naturalgasGateStation.getLongitude());
                }
        return entityWrapper;
        }
        }
